import os
from data_deal.function import  data_to_csv, df_get, stage_divide, stage_divide_info, stage_get,stage_add_polar
import pandas as pd
import numpy as np

rootpath='D:\\学习&科研\\华为手表项目\\华为数据\\subject'
typelist=['ecg','rrdata','singledetail','singlework','rri','ppg']
deal_path='D:\\学习&科研\\华为手表项目\\华为数据\\deal3'
# record = pd.read_csv('D:\\学习&科研\\华为手表项目\\华为数据\\试验记录表\\室内试验数据utf8.csv')
errorlist=[]
stage_info=[]
all_stages_df=pd.DataFrame()
number='1137-1-1'
# info_path=deal_path+'\\'+'stage'+'\\'+test+'-stage.csv'
# tocsv 可直接使用,个别问题再使用problemhanding 运行一遍

data_to_csv(number,rootpath,typelist,deal_path)
ecg_df=pd.read_csv(deal_path + '\\' + number[0:4] + '\\' + number + '-ecg' + '.csv')

print(deal_path + '\\' + number[0:4] + '\\' + number + '-ecg' + '.csv')
#             #使用for循环，将每个人的stage信息读取后,再使用rrdata，添加每个阶段的数据添加到一个总文件
number_stage_info=stage_divide_info(number,ecg_df)
stage_df=stage_divide(number,ecg_df)
print(stage_df)












# with open('D:\\学习&科研\\华为手表项目\\华为数据\\试验记录表\\stage_errorlog.txt', 'w') as f:
#     for index,rec in record.iterrows():
#             print(rec['number'],'正在处理')
#             number=rec['number']
#             # 读取 CSV 文件
#             # data_to_csv(number,rootpath,typelist,deal_path)
#             ecg_df=pd.read_csv(deal_path + '\\' + number[0:4] + '\\' + number + '-ecg' + '.csv')
            
            
#             #使用for循环，将每个人的stage信息读取后,再使用rrdata，添加每个阶段的数据添加到一个总文件
#             number_stage_info=stage_divide_info(number,ecg_df)
#             stage_info.append([number,number_stage_info])
#             f.write(f"{number}-{number_stage_info}\n")
#             f.flush()  # 刷新缓冲区
#             os.fsync(f.fileno())  # 同步到磁盘